//
//  KYInputMultilineView.m
//  YunKang
//
//  Created by leoking870 on 2017/10/1.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKInputMultilineView.h"

@interface YKInputMultilineView ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UITextView *inputTextView;

@end

@implementation YKInputMultilineView

-(instancetype)initWithTitle:(NSString *)title input:(NSString *)input {
    if (self = [super init]) {
        [self addSubview:self.titleLabel];
        [self addSubview:self.inputTextView];
        [self.subviews mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.mas_leading).offset(13);
            make.trailing.equalTo(self.mas_trailing).offset(-13);
        }];
        [self.subviews mas_alignAlongAxis:MASAxisTypeVertical fixedSpace:@8 leadSpace:8 tailSpace:8];
        [self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
        [self.inputTextView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(50);
        }];
        self.titleLabel.text = title;
        self.inputTextView.text = input;
    }
    return self;
}
- (void)setEditable:(BOOL)editable {
    _inputTextView.editable = editable;
    _inputTextView.backgroundColor = editable?[UIColor whiteColor]:[UIColor tf_colorWithHexString:@"#f2f2f2"];
    if (editable) {
        _inputTextView.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _inputTextView.layer.borderWidth = .5f;
        _inputTextView.layer.cornerRadius = 3.f;
        _inputTextView.layer.masksToBounds = YES;
    }
    else {
        _inputTextView.layer.borderColor = [UIColor clearColor].CGColor;
        _inputTextView.layer.borderWidth = .5f;
        _inputTextView.layer.cornerRadius = 3.f;
        _inputTextView.layer.masksToBounds = YES;
    }
}
-(BOOL)editable {
    return _inputTextView.editable;
}

- (void)setInput:(NSString *)input {
    self.inputTextView.text = input;
}
- (NSString *)input {
    return self.inputTextView.text;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor tf_colorWithHexString:@"#444444"];
        _titleLabel.font = [UIFont systemFontOfSize:14];
    }
    return _titleLabel;
}
- (UITextView *)inputTextView {
    if (!_inputTextView) {
        _inputTextView = [[UITextView alloc] init];
        _inputTextView.backgroundColor = [UIColor tf_colorWithHexString:@"#f2f2f2"];
        _inputTextView.textColor = [UIColor tf_colorWithHexString:@"#444444"];
    }
    return _inputTextView;
}

@end
